﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;

public partial class Main_Company_CompanyDetail : System.Web.UI.Page
{
    Datautility dut = new Datautility();
    
    protected void Page_Load(object sender, EventArgs e)
    {
         if (Session["userid"] == null)
        {
           // ScriptManager.RegisterStartupScript(Page, this.GetType(), "redirect", "window.open('../../login.aspx','_parent');", true);
            Response.Redirect("~/SessionExpire.aspx");
        }
        string compid = "";
        if (Request.QueryString["compid"] != null)
        {
            compid = Request.QueryString["compid"].ToString();
        }
       
       
        bindEditForm(compid);
        //Response.Write(compid);
    }

    private void bindEditForm(string compid)
    {
        DataTable dt = dut.getdata("select * from ACC_Company where compid="+compid);
        DataTable MyDT = new DataTable();
        MyDT.Columns.Add("CompId", typeof(string));
        MyDT.Columns.Add("CompName", typeof(string));
        MyDT.Columns.Add("TradingName", typeof(string));
        MyDT.Columns.Add("BType", typeof(string));
        MyDT.Columns.Add("Status", typeof(string));
        MyDT.Columns.Add("IsAccEnabled", typeof(string));
        MyDT.Columns.Add("IsInvcEnabled", typeof(string));
        MyDT.Columns.Add("IsInvrEnabled", typeof(string));
        MyDT.Columns.Add("BooksFromDate", typeof(DateTime));
        MyDT.Columns.Add("BooksEndDate", typeof(DateTime));


        MyDT.Columns.Add("Add1", typeof(string));
        MyDT.Columns.Add("Add2", typeof(string));
        MyDT.Columns.Add("Add3", typeof(string));
        MyDT.Columns.Add("Add4", typeof(string));
        MyDT.Columns.Add("place", typeof(string));
        MyDT.Columns.Add("PinCode", typeof(string));
        MyDT.Columns.Add("Country", typeof(string));
        MyDT.Columns.Add("State", typeof(string));
        MyDT.Columns.Add("Phone", typeof(string));
        MyDT.Columns.Add("Fax", typeof(string));
        MyDT.Columns.Add("Email", typeof(string));
        MyDT.Columns.Add("WebSite", typeof(string));
        MyDT.Columns.Add("Activity", typeof(string));
        MyDT.Columns.Add("Misc1", typeof(string));
        MyDT.Columns.Add("Misc2", typeof(string));


        MyDT.Columns.Add("Pan", typeof(string));
        MyDT.Columns.Add("PanDate", typeof(string));
        MyDT.Columns.Add("TDSNo", typeof(string));
        MyDT.Columns.Add("TDSDate", typeof(string));
        MyDT.Columns.Add("IsVatEnable", typeof(string));
        MyDT.Columns.Add("VatNo", typeof(string));
        MyDT.Columns.Add("VatDate", typeof(string));
        MyDT.Columns.Add("IsCSTEnable", typeof(string));
        MyDT.Columns.Add("CSTNo", typeof(string));
        MyDT.Columns.Add("CSTDate", typeof(String));
        MyDT.Columns.Add("ISSTEnabled", typeof(string));
        MyDT.Columns.Add("SERTNo", typeof(string));
        MyDT.Columns.Add("SERTNDate", typeof(string));
        MyDT.Columns.Add("ISCEEnabled", typeof(string));
        MyDT.Columns.Add("CEPAN", typeof(string));
        MyDT.Columns.Add("CEPANDate", typeof(string));
        MyDT.Columns.Add("ISLTENABLED", typeof(string));
        MyDT.Columns.Add("LTNO", typeof(string));
        MyDT.Columns.Add("LTNDATE", typeof(string));

        for (int i = 0; i < dt.Rows.Count; i++)
        {
            DataRow DR = MyDT.NewRow();
            DR["CompId"] = dt.Rows[i]["CompId"];
            DR["CompName"] = dt.Rows[i]["CompName"];
            DR["TradingName"] = dt.Rows[i]["TradingName"];
            string BType = dt.Rows[i]["BTYPE"].ToString();
            if (BType == "0")
            {
                DR["BType"] = dt.Rows[i]["OTHBTYPE"].ToString();
            }
            else
            {
                DR["BType"] = dut.getdata("Select BTypeName from ACC_BType where BTypeId=" + BType).Rows[0][0].ToString();
            }

            string OTHStatus = dt.Rows[i]["STATUSID"].ToString();
            if (OTHStatus == "0")
            {
                DR["Status"] = dt.Rows[i]["OTHStatus"].ToString();
            }
            else
            {
                DR["Status"] = dut.getdata("select CompStatusName from ACC_CompStatus where CompStatusId=" + OTHStatus).Rows[0][0].ToString();
            }
            string Accounting = dt.Rows[i]["IsAccEnabled"].ToString();
            if (Accounting == "True")
            {
                DR["IsAccEnabled"] = "Yes";
            }
            else
            {
                DR["IsAccEnabled"] = "No";
            }

            string Invoicing = dt.Rows[i]["IsInvcEnabled"].ToString();
            if (Invoicing == "True")
            {
                DR["IsInvcEnabled"] = "Yes";
            }
            else
            {
                DR["IsInvcEnabled"] = "No";
            }
            string Inventory = dt.Rows[i]["IsInvrEnabled"].ToString();
            if (Inventory == "True")
            {
                DR["IsInvrEnabled"] = "Yes";
            }
            else
            {
                DR["IsInvrEnabled"] = "No";
            }
            DR["BooksFromDate"] = dt.Rows[i]["BooksFromDate"];
            DR["BooksEndDate"] = dt.Rows[i]["BooksEndDate"];


            DR["Add1"] = dt.Rows[i]["Add1"];
            DR["Add2"] = dt.Rows[i]["Add2"];
            DR["Add3"] = dt.Rows[i]["Add3"];
            DR["Add4"] = dt.Rows[i]["Add4"];
            DR["place"] = dt.Rows[i]["place"];
            DR["PinCode"] = dt.Rows[i]["PinCode"];
            
            string countryid = dt.Rows[i]["country"].ToString();
            DR["Country"] = dut.getdata("Select CountryName from MAS_Country where CountryId=" + countryid).Rows[0][0].ToString();

            string stateid = dt.Rows[i]["StateID"].ToString();
            DR["State"] = dut.getdata("select StateName from MAS_State where StateID=" + stateid).Rows[0][0].ToString();
            
            DR["Phone"] = dt.Rows[i]["Phone"];
            DR["Fax"] = dt.Rows[i]["Fax"];
            DR["Email"] = dt.Rows[i]["Email"];
            DR["WebSite"] = dt.Rows[i]["WebSite"];
            DR["Activity"] = dt.Rows[i]["Activity"];
            DR["Misc1"] = dt.Rows[i]["Misc1"];
            DR["Misc2"] = dt.Rows[i]["Misc2"];



            DR["Pan"] = dt.Rows[i]["Pan"];
            DR["PanDate"] = dt.Rows[i]["PanDate"];
            DR["TDSNo"] = dt.Rows[i]["TDSNo"];
            ////Response.Write(Convert.ToDateTime(dt.Rows[i]["TDSDate"].ToString()).ToShortDateString());
            //if (Convert.ToDateTime(dt.Rows[i]["TDSDate"].ToString()).ToShortDateString() == "1/1/1900")
            //{
            //   // DR["TDSDate"] = "";
                
            //}
            //else
            //{
            //    DR["TDSDate"] = dt.Rows[i]["TDSDate"];
            //}

            string Vat = dt.Rows[i]["IsVatEnable"].ToString();
            if (Vat == "True")
            {
                DR["IsVatEnable"] = "Yes";
            }
            else
            {
                DR["IsVatEnable"] = "No";
            }
            DR["VatNo"] = dt.Rows[i]["VatNo"];
           // DR["VatDate"] = dt.Rows[i]["VatDate"];
            if (dt.Rows[i]["VatDate"].ToString() != "")
            {
                if (Convert.ToDateTime(dt.Rows[i]["VatDate"]).ToShortDateString() != "01/01/1900")
                {
                    DR["VatDate"] = string.Format("{0:dd-MMM-yy}", Convert.ToDateTime(dt.Rows[i]["VatDate"].ToString()));
                }
            }
            else
            {
                DR["VatDate"] = "";
            }

            string InterState = dt.Rows[i]["IsCSTEnable"].ToString();
            if (InterState == "True")
            {
                DR["IsCSTEnable"] = "Yes";
            }
            else
            {
                DR["IsCSTEnable"] = "No";
            }
            DR["CSTNo"] = dt.Rows[i]["CSTNo"];
            //DR["CSTDate"] = dt.Rows[i]["CSTDate"];

            if (dt.Rows[i]["CSTDate"].ToString() != "")
            {
                if (Convert.ToDateTime(dt.Rows[i]["CSTDate"]).ToShortDateString() != "01/01/1900")
                {
                    DR["CSTDate"] = string.Format("{0:dd-MMM-yy}", Convert.ToDateTime(dt.Rows[i]["CSTDate"].ToString()));
                }
            }
            else
            {
                DR["CSTDate"] = "";
            }


            string Service_Tax = dt.Rows[i]["ISSTEnabled"].ToString();
            if (Service_Tax == "True")
            {
                DR["ISSTEnabled"] = "Yes";
            }
            else
            {
                DR["ISSTEnabled"] = "No";
            }
            DR["SERTNo"] = dt.Rows[i]["SERTNo"];
           // DR["SERTNDate"] = dt.Rows[i]["SERTNDate"];
            if (dt.Rows[i]["SERTNDate"].ToString() != "")
            {
                if (Convert.ToDateTime(dt.Rows[i]["SERTNDate"]).ToShortDateString() != "01/01/1900")
                {
                    DR["SERTNDate"] = string.Format("{0:dd-MMM-yy}", Convert.ToDateTime(dt.Rows[i]["SERTNDate"].ToString()));
                }
            }
            else
            {
                DR["SERTNDate"] = "";
            }


            string Central_Excise = dt.Rows[i]["ISCEEnabled"].ToString();
            if (Central_Excise == "True")
            {
                DR["ISCEEnabled"] = "Yes";
            }
            else
            {
                DR["ISCEEnabled"] = "No";
            }
            DR["CEPAN"] = dt.Rows[i]["CEPAN"];
           // DR["CEPANDate"] = dt.Rows[i]["CEPANDate"];

            if (dt.Rows[i]["CEPANDate"].ToString() != "")
            {
                if (Convert.ToDateTime(dt.Rows[i]["CEPANDate"]).ToShortDateString() != "01/01/1900")
                {
                    DR["CEPANDate"] = string.Format("{0:dd-MMM-yy}", Convert.ToDateTime(dt.Rows[i]["LTNDATE"].ToString()));
                }
            }
            else
            {
                DR["CEPANDate"] = "";
            }
           


            string Luxury_Tax = dt.Rows[i]["ISLTENABLED"].ToString();
            if (Luxury_Tax == "True")
            {
                DR["ISLTENABLED"] = "Yes";
            }
            else
            {
                DR["ISLTENABLED"] = "No";
            }
            DR["LTNO"] = dt.Rows[i]["LTNO"];
            if (dt.Rows[i]["LTNDATE"].ToString() != "")
            {
                if (Convert.ToDateTime(dt.Rows[i]["LTNDATE"]).ToShortDateString() != "01/01/1900")
                {
                    DR["LTNDATE"] = string.Format("{0:dd-MMM-yy}", Convert.ToDateTime(dt.Rows[i]["LTNDATE"].ToString()));
                }
            }
            else
            {
                DR["LTNDATE"] = "";
            }
            
            MyDT.Rows.Add(DR);

        }
        detailview.DataSource = MyDT;
        detailview.DataBind();
    }

       


}
